package com.lzh.others.basejava.Exception_12;

/**
 * @author by lzh
 * @Classname WhoCalled
 * @Description 12.6.1 栈轨迹
 * 从最里层抛到最外层
 * 每一个元素都表示栈中的一帧，即一个方法调用
 * @Date 2022/6/29 22:29
 */
public class WhoCalled {
    static void f() {
        //Generate an exception to fill in the stack trace
        try {
            throw new Exception();
        } catch (Exception e) {
            e.printStackTrace();
            for (StackTraceElement stackTraceElement : e.getStackTrace()) {
                System.out.println(stackTraceElement.getMethodName() + " " + stackTraceElement.getClassName());
                System.out.println("stackTraceElement = " + stackTraceElement);
            }
        }
    }

    static void g() {
        f();
    }

    static void h() {
        g();
    }

    public static void main(String[] args) {
        f();
        System.out.println("----------------------------");
        g();
        System.out.println("----------------------------");
        h();
        System.out.println("----------------------------");
    }
}
